import os
from datetime import time
import time as t
from CSYNAC.Node import Node


class Log():
    def __init__(self,eventID,time,node_name:str=None,
                 message:str=None,mtype:str="normal"):
        self.time=time
        self.node = node_name
        self.message = message
        self.mtype = mtype
        self.eventID = eventID


class LogKeeper():
    def __init__(self):
        self.logs = []

    def add_log(self,node:Node,eventID:str,mtype,message:str):
        self.logs.append(Log(
            eventID,self.time(),node.nodename,message=message,mtype=mtype
        ))

    def time(self):
        return time()

    def clear(self):
        # pass # 话说真的需要这个函数吗?
        del self.logs
        self.logs = []

    def dump(self,):
        pass

    def call_back(self,f):
        return f(self)

class SimpleLogger():
    def __init__(self,path:str):
        self.path = path

    def w(self,s):
        with open(f"{self.path}/log" ,'w') as f:
            f.write(t.time(),'|',s)
    